package com.itwxz.forum.controller.pc;


import cn.dev33.satoken.annotation.SaIgnore;
import com.itwxz.common.annotation.Log;
import com.itwxz.common.core.controller.BaseController;
import com.itwxz.common.core.domain.AjaxResult;
import com.itwxz.common.core.page.TableDataInfo;
import com.itwxz.common.enums.BusinessType;
import com.itwxz.common.utils.poi.ExcelUtil;
import com.itwxz.forum.domain.po.ForumConfig;
import com.itwxz.forum.service.ForumConfigService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 手机端论坛参数配置Controller
 *
 * @author gastronome
 * @date 2025-05-18
 */
@Tag(name = "手机端论坛参数配置Controller")
@RestController
@SaIgnore
@RequestMapping("/forum/config")
public class ForumConfigController extends BaseController {
	@Autowired
	private ForumConfigService forumConfigService;

	/**
	 * 查询手机端论坛参数配置列表
	 */
	@Operation(summary = "查询手机端论坛参数配置列表")
	@PreAuthorize("@ss.hasPermi('forum:config:list')")
	@GetMapping("/list")
	public TableDataInfo list(ForumConfig forumConfig) {
		startPage();
		List<ForumConfig> list = forumConfigService.selectForumConfigList(forumConfig);
		return getDataTable(list);
	}

	/**
	 * 导出手机端论坛参数配置列表
	 */
	@Operation(summary = "导出手机端论坛参数配置列表")
	@PreAuthorize("@ss.hasPermi('forum:config:export')")
	@Log(title = "手机端论坛参数配置", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, ForumConfig forumConfig) {
		List<ForumConfig> list = forumConfigService.selectForumConfigList(forumConfig);
		ExcelUtil<ForumConfig> util = new ExcelUtil<>(ForumConfig.class);
		util.exportExcel(response, list, "手机端论坛参数配置数据");
	}

	/**
	 * 获取手机端论坛参数配置详细信息
	 */
	@Operation(summary = "获取手机端论坛参数配置详细信息")
	@PreAuthorize("@ss.hasPermi('forum:config:query')")
	@GetMapping(value = "/{configId}")
	public AjaxResult getInfo(@PathVariable("configId") Long configId) {
		return success(forumConfigService.getById(configId));
	}

	/**
	 * 新增手机端论坛参数配置
	 */
	@Operation(summary = "新增手机端论坛参数配置")
	@CacheEvict(value = "config", key = "'forum'")
	@PreAuthorize("@ss.hasPermi('forum:config:add')")
	@Log(title = "手机端论坛参数配置", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody ForumConfig forumConfig) {
		return toAjax(forumConfigService.save(forumConfig));
	}

	/**
	 * 修改手机端论坛参数配置
	 */
	@Operation(summary = "修改手机端论坛参数配置")
	@CacheEvict(value = "config", key = "'forum'")
	@PreAuthorize("@ss.hasPermi('forum:config:edit')")
	@Log(title = "手机端论坛参数配置", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody ForumConfig forumConfig) {
		return toAjax(forumConfigService.updateById(forumConfig));
	}

	/**
	 * 删除手机端论坛参数配置
	 */
	@Operation(summary = "删除手机端论坛参数配置")
	@CacheEvict(value = "config", key = "'forum'")
	@PreAuthorize("@ss.hasPermi('forum:config:remove')")
	@Log(title = "手机端论坛参数配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{configIds}")
	public AjaxResult remove(@PathVariable Long[] configIds) {
		return toAjax(forumConfigService.removeByIds(Arrays.asList(configIds)));
	}
}
